﻿<%@ Page Culture="auto" UICulture="auto" Title="Custom constraints" Language="C#"
    MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="CustomConstraint.aspx.cs"
    Inherits="BM.Tools.WebControls.MForm.Example.Constraints.CustomConstraint" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ContentPlaceHolderID="Demonstration" runat="server">

    <script type="text/javascript">
        function EvenOnly(value, id) {
            var intValue = parseInt(value);
            return intValue % 2 == 0;
        }
    </script>

    <p>
        Provide an even value (check out the EvenOnlyValidate server
        side method and EvenOnly javascript function)
    </p>
    <mf:RootValidator runat="server" ControlToValidate="Root1" />
    <mf:Root ID="Root1" runat="server">
        <Contents>
            <mf:Branch runat="server" Name="CustomConstraintExample">
                <Contents>
                    <mf:Leaf Name="EvenOnly" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:CustomConstraint OnServerValidate="EvenOnlyValidate" ClientFunctionName="EvenOnly"
                                runat="server" />
                        </Additions>
                    </mf:Leaf>
                    <mf:Leaf Name="EvenOnlyServerOnlyValidation" runat="server" DataType="Int">
                        <Additions>
                            <mfadd:CustomConstraint OnServerValidate="EvenOnlyValidate" runat="server" />
                        </Additions>
                    </mf:Leaf>
                </Contents>
            </mf:Branch>
        </Contents>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The custom constraint is a constraint that allows defining custom client and server-side
        validation
    </p>
    <p>
        To check the constraint on the client side a <code>ClientFunctionName</code> property
        should be set.
    </p>
    <p>
        If it is not set, there will be no client-side validation
    </p>
    <p>
        The implementation of function should look like this:
        <br />
        <code>function</code> clientFunctionName (<code>value</code>, <code>client_id</code>)
    </p>
    <p>
        To check the function on the server side, the <code>OnServerValidate</code> event
        should be implemented. If it is not implemented, the validation will by default
        return true on server side.
    </p>
    <div class="Remark">
        <p>
            The <code>CustomConstraint</code> may closely resemble the ASP.NET <code>CustomValidator</code>
            control. You should however notice that the function definition is different</p>
    </div>
</asp:Content>
